package com.example.mymatch.controller;

import com.example.mymatch.model.Work;
import com.example.mymatch.service.IWorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * WorkController层
 * 编写者：杨滢
 */

@Api(tags = "打卡")
@RestController
public class WorkController {
    @Autowired
    private IWorkService workService;//对某个业务服务的内容进行定义规范  编写者：杨滢

    @ApiOperation(value = "查询所有打卡信息",notes = "获取打卡信息返回json字符串")
    @RequestMapping("/getStr11")
    public String getWork(){
        return "My work";
    }
    @CrossOrigin
    @ApiOperation(value = "对打卡信息的添加方法")
    @GetMapping("/addWork")
    public int addWork(Work work){
        System.out.println("进入添加打卡信息接口");
        return workService.insertWork(work);
    }

    @GetMapping("getAll11")
    @ApiOperation(value = "对打卡信息的查询方法")
    public List<Work> getAllWork(Work work){
        System.out.println("进入查询方法");

        List<Work> listWork=workService.getAllWork(work);

        return listWork;
    }

    @PutMapping("/editWork")
    @ApiOperation(value = "对打卡信息的修改方法")
    public int EditWork(@RequestBody Work work){
        System.out.println("进入打卡修改方法");
        return workService.updateWork(work);
    }

    @GetMapping("/delWork")
    @ApiOperation(value = "对打卡信息的删除方法")
    public int Delete(int id){
        System.out.println("进入打卡删除方法");
        int returnValue=0;
        if (id!=0){
            Work work=new Work();
            work.setId(id);
            returnValue= workService.deleteWork(work);
        }
        return returnValue;
    }

    @GetMapping("/getOne11")
    @ApiOperation(value = "对单条打卡信息的查询方法")
    public  Work getWork(int id){
        Work work=new Work();
        System.out.println("进入打卡查询方法");
        if (id!=0){
            Work work1=new Work();
            work1.setId(id);
            work=workService.getWork(work1);
            System.out.println("返回的数据集合为："+work.getWorkName());
        }
        return work;
    }
}
